package com.arges.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.arges.web.common.Constant;
import com.arges.web.domain.bean.DocBean;

/**
 * 防止无session登录，过滤请求路径
 * 
 * @author arges
 *
 */
public class ClientSessionFilter implements Filter
{
	public ClientSessionFilter()
	{
	}

	public void destroy()
	{
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
			ServletException
	{
		HttpServletRequest request2 = (HttpServletRequest) request;
		HttpServletResponse response2 = (HttpServletResponse) response;
		String uri = request2.getRequestURI();
		DocBean user = (DocBean) request2.getSession().getAttribute("currentUser");
		// 此处过滤掉登录的url和单点登录地址以及图片，静态资源 uri.contains(".do")
		if (uri.contains("mainInit.do") || uri.endsWith(".js") || uri.endsWith(".gif") || uri.endsWith(".png")
				|| uri.endsWith(".jpg") || uri.endsWith(".jpeg") || uri.endsWith(".woff") || uri.endsWith(".ttf")
				|| uri.endsWith(".css") || null != user || uri.equals("/graduation_project/")
				|| uri.equals("/graduation_project/jsp/login.jsp")
				|| uri.equals("/graduation_project/login/getCode.do") || uri.contains("login.do"))
		{
			chain.doFilter(request, response);
		}
		else
		{
			response2.sendRedirect("/" + Constant.CLIENT_NAME + "/jsp/login.jsp");
		}
	}

	public void init(FilterConfig fConfig) throws ServletException
	{
	}

}
